package com.javabase.y2022.m04.day0423.v0069.v1;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2022/4/23 上午 08:49
 * @version: 1.0
 */
public class Solution {
    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.mySqrt(2147395600));
    }
    public int mySqrt(int x){
        if( x == 0){
            return 0;
        }
        int ans = 1;
        for(int i =1; i <= x/2; i++){
            // 兩個int相乘要注意是否是long
            long ti1 = (long)i * i;
            long ti2 = (long)(i+1)*(i+1);
            if(ti1 <= x && ti2 > x){
                ans = i;
                break;
            }
        }
        return ans;
    }
}
